//
//  LoginViewController.m
//  ZhiHuDaily
//
//  Created by albert on 16/9/4.
//  Copyright © 2016年 albert. All rights reserved.
//

#import "LoginViewController.h"
#import "NavBarView.h"
#import "JKAccountManager.h"
#import "JKProgressHUD.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userAccountField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
/** 导航条 */
@property (nonatomic, weak) NavBarView *navBarView;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NavBarView *navBarView = [NavBarView barViewWithTitle:@"登录" showBackTitle:NO];
    [self.view addSubview:navBarView];
    self.navBarView = navBarView;
    [self.navBarView changeToDaySkin];
    __weak typeof(self) weakSelf = self;
    [self.navBarView setBackBtnClickBlock:^(UIButton *btn) {
        [weakSelf dismissViewControllerAnimated:YES completion:nil];
    }];
    
    self.loginBtn.layer.borderColor = [[UIColor blackColor] colorWithAlphaComponent:0.3].CGColor;
    self.loginBtn.layer.borderWidth = 1;
}

- (IBAction)loginBtnClick:(id)sender {
    if (!self.userAccountField.hasText || !self.pwdField.hasText) {
        [JKProgressHUD showErrorWithStatus:@"请输入帐号\\密码"];
        return;
    }
    BOOL success = [JKAccountManager loginWithUserName:self.userAccountField.text password:self.pwdField.text];
    if (success) {
        [self dismissViewControllerAnimated:YES completion:^{
            [JKProgressHUD showSuccessWithStatus:@"登录成功！"];
        }];
    }else{
        [JKProgressHUD showErrorWithStatus:@"帐号\\密码错误"];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
